<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主页</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            height: 100vh;
            margin: 0;
        }

        /* 左侧导航栏样式 */
        nav {
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 200px;
            margin: 80px 20px 20px 20px;
            /* 调整上边距，避免被顶部导航栏遮挡 */
        }

        nav ul {
            list-style-type: none;
            padding: 0;
        }

        nav ul li {
            margin-bottom: 10px;
        }

        nav ul li a {
            display: block;
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
            box-sizing: border-box;
            color: #007BFF;
            text-decoration: none;
        }

        nav ul li a:hover,
        nav ul li a.active {
            background-color: #007BFF;
            color: #fff;
        }

        /* 顶部用户信息区域样式 */
        header {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: flex-end;
            align-items: center;
            z-index: 1;
            /* 确保顶部导航栏在最上层 */
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .avatar {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            margin-right: 10px;
        }

        #logout-btn {
            padding: 10px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        #logout-btn:hover {
            background-color: #0056b3;
        }

        /* 主内容区域样式 */
        main {
            flex: 1;
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            margin: 80px 20px 20px 0;
        }

        iframe {
            width: 100%;
            height: 100%;
            border: none;
        }
    </style>
</head>

<body>
<!-- 顶部用户信息区域 -->
<header>
    <div class="user-info">
        <img src="http://st58q4cqz.hn-bkt.clouddn.com/gugugu.jpg" alt="头像"
             class="avatar">
        <button id="logout-btn">退出登录</button>
    </div>
</header>

<!-- 左侧导航栏 -->
<nav>
    <ul>
        <li><a href="welcome.html" data-target="main-iframe">欢迎页面</a></li>
        <li><a href="purchase.html" data-target="main-iframe">购买页面</a></li>
        <li><a href="orderHistory.html" data-target="main-iframe">订单页面</a></li>
    </ul>
</nav>

<!-- 主内容区域 -->
<main>
    <iframe id="main-iframe" src="welcome.html"></iframe>
</main>

<script>
    // 退出登录按钮点击事件
    const logoutBtn = document.getElementById('logout-btn');
    logoutBtn.addEventListener('click', function () {
        // 删除 cookie 里的 token
        document.cookie = "jwtToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
        // 这里可以添加实际的退出登录逻辑，例如跳转到登录页面
        alert('你已退出登录');
        window.location.href = 'login.html';
    });

    // 左侧导航栏点击事件
    const nav = document.querySelector('nav');
    nav.addEventListener('click', function (e) {
        if (e.target.tagName === 'A') {
            e.preventDefault();
            const url = e.target.getAttribute('href');
            const targetIframe = document.getElementById(e.target.getAttribute('data-target'));
            targetIframe.src = url;

            // 移除所有导航链接的 active 类
            const navLinks = document.querySelectorAll('nav ul li a');
            navLinks.forEach(link => {
                link.classList.remove('active');
            });

            // 给当前点击的导航链接添加 active 类
            e.target.classList.add('active');
        }
    });
</script>
</body>

</html>